package com.gaga.metadata.common.enums;

/**
 * 聚类类型
 */
public enum SqlFunctionType {
    SUM("SUM", "求和", false),
    REPLACE("REPLACE", "保留最新值", true),
    MAX("MAX", "保留最大值", false),
    COUNT("COUNT", "计数", false),
    COUNT_DISTINCT("COUNT_DISTINCT", "去重计数", false),
    MIN("MIN", "保留最小值", false),
    CASEWHEN("CASEWHEN", "case when 函数", true),
    IFNULL("IFNULL", "IFNULL函数", true),
    DATE_FORMAT("DATEFORMAT", "时间转换函数", true),
    COLUMN_CONDITION("COLUMN_CONDITION", "列条件拼接器", true),
    VALUE("VALUE", "常量拼接处理", true),
    TO_CHAR("TO_CHAR", "字符串转换函数", true),
    GT(">", "大于", true),
    GTE(">=", "大于等于", true),
    LT("<", "大于", true),
    LTE("<=", "大于等于", true),
    TO_DATE("TO_DATE", "日期转换函数", true),
    DIM_TO_CHAR("DIM_TO_CHAR", "时间维度列字符串转换函数", true),
    AVG("AVG", "平均数函数", false),
    DISTINCT("DISTINCT", "去重函数", true),
    NOW("NOW", "时间函数", true),
    IN("IN", "包含", true);


    private final String code;
    private final String info;
    /**
     * 是否需要groupBy
     */
    private final Boolean nendGroupBy;

    SqlFunctionType(String code, String info, Boolean nendGroupBy) {
        this.code = code;
        this.info = info;
        this.nendGroupBy = nendGroupBy;
    }

    public String getCode() {
        return code;
    }

    public String getInfo() {
        return info;
    }

    public Boolean getNendGroupBy() {
        return nendGroupBy;
    }

    public static SqlFunctionType ofCode(String oprCode) {
        for (SqlFunctionType sqlFunctionType : values()) {
            if (sqlFunctionType.code.equalsIgnoreCase(oprCode)) {
                return sqlFunctionType;
            }
        }
        return null;
    }
}
